package com.qifenqian.turbot.module.ui.marketing

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseFragment
import com.qifenqian.turbot.module.adapter.itemdecoration.LinearItemDecoration
import com.qifenqian.turbot.module.adapter.marketing.MarketingRvAdapter1
import com.qifenqian.turbot.module.adapter.marketing.MarketingRvAdapter2
import com.qifenqian.turbot.module.adapter.marketing.MarketingRvAdapter3
import com.qifenqian.turbot.module.adapter.marketing.MarketingRvAdapter4
import com.qifenqian.turbot.module.contract.MarketingContract
import com.qifenqian.turbot.module.entity.response.marketing.MarketingHomeEntity
import com.qifenqian.turbot.module.presenter.MarketingPresenter
import kotlinx.android.synthetic.main.fragment_marketing.view.*

/**
 * @author H
 * @createDate 2019/1/3 9:46
 * @description 营销工具
 * @see
 * @since
 */
class MarketingFragment : BaseFragment<MarketingPresenter, MarketingContract.View>(), MarketingContract.View {

    override fun bindLayoutId(): Int {
        return R.layout.fragment_marketing
    }

    override fun bindPresenter(): MarketingPresenter? {
        return MarketingPresenter(activity!!, this)
    }

    private var mListMarkingEntities1: MutableList<String> = mutableListOf("特价菜", "单品折扣")
    private var mListMarkingEntities2: MutableList<String> = mutableListOf("闲时折扣", "分享优惠券")
    private var mListMarkingEntities3: MutableList<String> = mutableListOf("满减")
    private var mListMarkingEntities4: MutableList<String> = mutableListOf("买单折扣")

    override fun initial(view: View) {
        mPresenter?.getMarketingPage()
        view.rv_marketing_1.addItemDecoration(LinearItemDecoration(activity as Context, LinearItemDecoration.HORIZONTAL, 8))
        view.rv_marketing_2.addItemDecoration(LinearItemDecoration(activity as Context, LinearItemDecoration.HORIZONTAL, 8))
        view.rv_marketing_3.addItemDecoration(LinearItemDecoration(activity as Context, LinearItemDecoration.HORIZONTAL, 8))
        view.rv_marketing_4.addItemDecoration(LinearItemDecoration(activity as Context, LinearItemDecoration.HORIZONTAL, 8))
        view.rv_marketing_1.layoutManager = LinearLayoutManager(activity as Context, LinearLayoutManager.HORIZONTAL, false)
        view.rv_marketing_2.layoutManager = LinearLayoutManager(activity as Context, LinearLayoutManager.HORIZONTAL, false)
        view.rv_marketing_3.layoutManager = LinearLayoutManager(activity as Context, LinearLayoutManager.HORIZONTAL, false)
        view.rv_marketing_4.layoutManager = LinearLayoutManager(activity as Context, LinearLayoutManager.HORIZONTAL, false)
        val marketingRvAdapter1 = MarketingRvAdapter1(mListMarkingEntities1)
        val marketingRvAdapter2 = MarketingRvAdapter2(mListMarkingEntities2)
        val marketingRvAdapter3 = MarketingRvAdapter3(mListMarkingEntities3)
        val marketingRvAdapter4 = MarketingRvAdapter4(mListMarkingEntities4)
        view.rv_marketing_1.adapter = marketingRvAdapter1
        view.rv_marketing_2.adapter = marketingRvAdapter2
        view.rv_marketing_3.adapter = marketingRvAdapter3
        view.rv_marketing_4.adapter = marketingRvAdapter4
        marketingRvAdapter1.setOnItemClickListener { adapter, view, position ->
            when (position) {
                0 -> SpecialDishActivity.startThis(activity!!)
                1 -> DiscountDishActivity.startThis(activity!!)
            }
        }
        marketingRvAdapter2.setOnItemClickListener { adapter, view, position ->
            when (position) {
                0 -> FreeTimeDiscountActivity.startThis(activity!!)
                1 -> ShareDiscountActivity.startThis(activity!!)
            }
        }
        marketingRvAdapter3.setOnItemClickListener { adapter, view, position ->
            when (position) {
                0 -> FullReductionActivity.startThis(activity!!)
            }
        }
        marketingRvAdapter4.setOnItemClickListener { adapter, view, position ->
            when (position) {
                0 -> EarlyPayDiscountActivity.startThis(activity!!)
            }
        }
    }

    override fun getMarketingPageResult(isSuccess: Boolean, code: Int, msg: String?, marketingHomeEntity: MarketingHomeEntity?) {
        if (isSuccess) {

        } else {

        }
    }
}
